/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_fixed;


import com.yuecai.modules.yc_fixed.domain.YcFixed;
import com.yuecai.modules.yc_fixed.service.YcFixedService;
import com.yuecai.modules.yc_fixed.service.dto.YcFixedQueryCriteria;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @website https://el-admin.vip
* @author dm
* @date 2020-07-12
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "yc_fixed管理")
@RequestMapping("/api/ycFixed")
public class YcFixedController {

    private final YcFixedService ycFixedService;


    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, YcFixedQueryCriteria criteria) throws IOException {
        ycFixedService.download(ycFixedService.queryAll(criteria), response);
    }

    @GetMapping
    public ResponseEntity<Object> query(YcFixedQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(ycFixedService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Object> create(@Validated @RequestBody YcFixed resources){
        return new ResponseEntity<>(ycFixedService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    public ResponseEntity<Object> update(@Validated @RequestBody YcFixed resources){
        ycFixedService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
        ycFixedService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}